package com.haojiang.mh.service

import android.bluetooth.BluetoothAdapter
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.haojiang.mh.cache.Const
import com.haojiang.mh.service.event.OneEvent
import com.haojiang.mh.utils.KLog
import org.greenrobot.eventbus.EventBus

/**
 * 蓝牙关闭监听
 *
 * Created by ZapFive on 2019-05-26.
 *
 * wuzhuang@mirahome.me
 */
class BluetoothOffReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        if ("android.bluetooth.adapter.action.STATE_CHANGED" == intent?.action) {
            when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) {
                BluetoothAdapter.STATE_TURNING_ON -> {
                    KLog.d("STATE_TURNING_ON")
                }
                BluetoothAdapter.STATE_ON -> {
                    KLog.d("STATE_ON")
                }
                BluetoothAdapter.STATE_TURNING_OFF -> {
                    KLog.d("STATE_TURNING_OFF")
                }
                BluetoothAdapter.STATE_OFF -> {
                    KLog.d("STATE_OFF")
                    EventBus.getDefault().post(OneEvent(Const.BLUETOOTH_OFF))
                }
            }
        }
    }
}